import { memo } from "react";

import { Upload, Button } from "antd";
import { getFileInfo } from "@/utils/file/chunkUtils";
import PropTypes from "prop-types";

const FileUploadComponent = ({ title, path, callback, ...resProps }) => {
  const beforeUpload = async (file) => {
    const value = await getFileInfo(file);
    callback && callback(value);
    return false; // 阻止自动上传
  };

  return (
    <Upload showUploadList={false} beforeUpload={(file) => beforeUpload(file)}>
      <Button {...resProps}>{title}</Button>
    </Upload>
  );
};
FileUploadComponent.propTypes = {
  title: PropTypes.string,
  path: PropTypes.string,
  callback: PropTypes.func,
};
export default memo(FileUploadComponent);
